<template>
    <view class="mobile-input-container">
        <input placeholder="请输入手机号" :value="mobile" placeholder-class="input-placeholder" maxlength="11" type="digit" @input="$emit('update:mobile', $event.detail.value)" />
        <image v-show="showClear" src="@/static/img/clear.png" class="clear" @click="clearMobile"></image>
    </view>
</template>

<script setup>
import { ref, watch } from 'vue';
const props = defineProps({
    mobile: String
});
const emit = defineEmits(['update:mobile']);
const showClear = ref(false);
watch(
    () => props.mobile,
    (newValue) => {
        showClear.value = newValue.length > 0;
    }
);
function clearMobile() {
    emit('update:mobile', '');
}
</script>

<style lang="scss" scoped>
@import '@/static/css/common.scss';
.mobile-input-container {
    @extend .row-layout;
    margin: $scale * 5px 0;
    padding: $scale * 0rpx $scale * 10rpx;
    justify-content: center;
    align-items: center;
    border-radius: $scale * 8rpx;
    .clear {
        width: $scale * 16rpx;
        height: $scale * 16rpx;
        padding: $scale * 5rpx;
    }
    input {
        color: black;
        font-size: $scale * 22rpx;
        padding: $scale * 10rpx 0;
        flex: 1;
    }
    .input-placeholder {
        color: #979797;
        font-size: $scale * 16rpx;
        padding: $scale * 10rpx 0;
        flex: 1;
    }
}
</style>
